package com.sgb.knowledgeshare.view.activity;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import android.view.View;
import com.sgb.knowledgeshare.R;
import com.sgb.knowledgeshare.databinding.ActivityShareMinfansBinding;
import com.sgb.knowledgeshare.entity.ShareUserInfoEntity;
import com.sgb.knowledgeshare.view.fragment.ShareMinFansListFragment;
import com.sgb.knowledgeshare.viewmodel.ShareMinFansModel;
import com.swgk.core.base.AppActivity;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;
import com.swgk.core.util.SharedPreferenceUtil;
import java.util.ArrayList;

/**
 * Created by fq on 2020/9/11 0011
 * Description： 分享-我-关注和粉丝
 */
public class ShareMinFansActivity extends AppActivity {
    public static final int MIN_ATTENTION = 0;//关注
    public static final int MIN_FANS = 1;//粉丝
    public static final String TYPE = "type";//区分加载那个界面
    ShareMinFansModel viewmodel;
    private ActivityShareMinfansBinding binding;
    private String userid;
    private ArrayList<Fragment> mFragments;

    public static void start(Context context ,int  type ) {
        Intent intent = new Intent();
        intent.putExtra(TYPE,type);
        intent.setClass(context, ShareMinFansActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_share_minfans);
        viewmodel = new ViewModelProvider(this).get(ShareMinFansModel.class);
        viewmodel.setActivity(ShareMinFansActivity.this);
        View decor = getWindow().getDecorView();
        decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        binding.include.ivBack.setOnClickListener(this);
        userid = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.USER_NO, "");

    }

    @Override
    protected void onResume() {
        super.onResume();
        initdata();
    }

    private void initdata() {
        viewmodel.getUserHomePage(userid);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.iv_back) {//返回
            finish();
        }
    }


    public void setUserData(ShareUserInfoEntity data) {
        binding.include.titleView.setText(data.getName());
        String[] titles = {"关注  " + data.getFollow(), "粉丝  " + data.getFens()};
        mFragments = new ArrayList<>();
        mFragments.add(ShareMinFansListFragment.newInstance( MIN_ATTENTION));
        mFragments.add(ShareMinFansListFragment.newInstance( MIN_FANS));
        SlidingFragmentPagerAdapter mAdapetr = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        binding.viewpager.setAdapter(mAdapetr);
        binding.viewpager.setOffscreenPageLimit(titles.length - 1);
        binding.tablayout.setViewPager(binding.viewpager);
        binding.viewpager.setCurrentItem(getIntent().getIntExtra(TYPE,0));
    }
    public void updateFragmentViews(){
        initdata();
    }
}
